package org.komarichin.services;

import org.komarichin.beans.ILanguage;
import org.komarichin.beans.IPartition;
import org.komarichin.beans.dao.IPartitionDAO;
import org.komarichin.beans.service.IPartitionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;

/**
 * User: Mykhaylo Komarichyn
 * Date: 16.12.2009
 * Time: 15:19:10
 */
@Service
public class PartitionService<PK> implements IPartitionService<PK> {
    private static final long serialVersionUID = -8824033391029198802L;
    private static final Logger log = LoggerFactory.getLogger(PartitionService.class);
    @Autowired
    protected IPartitionDAO<IPartition<PK>, PK> partitionDAO;

    public PartitionService() {
        log.debug("instance of partition service created.");
    }

    @Override
    public IPartition<PK> save(IPartition<PK> partition) {
        return partitionDAO.save(partition);
    }

    @Override
    public void saveOrUpdate(IPartition<PK> partition) {
        partitionDAO.saveOrUpdate(partition);
    }

    @Override
    public void remove(IPartition<PK> partition) {
        partitionDAO.remove(partition.getId());
    }

    @Override
    public void remove(PK id) {
        partitionDAO.remove(id);
    }

    @Override
    public IPartition<PK> findById(PK id) {
        return partitionDAO.findById(id);
    }

    @Override
    public Collection<IPartition<PK>> getAll() {
        return partitionDAO.getAll();
    }

    @Override
    public Collection<IPartition<PK>> getAll(ILanguage lang) {
        return partitionDAO.getAll(lang);
    }

    @Override
    public Collection<IPartition<PK>> getByCriteries(int start, int limit, String fieldName, boolean order) {
        return partitionDAO.getEntityByParams(start, limit, fieldName, order);
    }

    @Override
    public Collection<IPartition<PK>> getByCriteries(ILanguage lang, int start, int limit, String fieldName, boolean order) {
        return partitionDAO.getEntityByParams(start, limit, fieldName, order, lang);
    }
}
